<template>
  <div v-if="fullscreenLoading" :style="{'background-color': '#EBEEF5', 'min-height': screenHeight + 'px'}">
    <div :style="{'width': '1200px', 'margin': '0 auto', 'display': 'flex'}">
      <div class="con-line">
        <div class="con-card">
          <div style="padding: 0 30px 0 30px;">
            <i class="el-icon-office-building" style=" font-size: 74px; color: #FFFFFF" />
          </div>
          <div style="color: #FFFFFF; font-size: 20px;">企业基本信息</div>
        </div>
        <div class="con-btn">
          <el-tag :type="base | baseFilter">{{ base | baseFormat }}</el-tag>
          <div>
            <el-button type="primary" @click="toBase">{{ baseBtn }}</el-button>
          </div>
        </div>
      </div>
      <div class="con-line">
        <div class="con-card">
          <div style="padding: 0 30px 0 30px;">
            <i class="el-icon-monitor" style=" font-size: 74px; color: #FFFFFF" />
          </div>
          <div style="color: #FFFFFF; font-size: 20px;">{{ year }}<br>数智生态诊断</div>
        </div>
        <div class="con-btn">
          <el-tag :type="test | testFilter">{{ test | testFormat }}</el-tag>
          <div>
            <template v-if="test === '1'">
              <el-button type="primary" @click="toReview">查看填报信息</el-button>
            </template>
            <el-button :type="test | testButton" @click="baseFind(1)">{{ testBtn }}</el-button>
          </div>
        </div>
      </div>
      <div class="con-line">
        <div class="con-card">
          <div style="padding: 0 30px 0 30px;">
            <i class="el-icon-document" style=" font-size: 74px; color: #FFFFFF" />
          </div>
          <div style="color: #FFFFFF; font-size: 20px;">问卷调查</div>
        </div>
        <div class="con-btn">
          <el-tag :type="question | testFilter">{{ question | testFormat }}</el-tag>
          <div>
            <el-button :type="question | testButton" @click="baseFind(2)">{{ quesBtn }}</el-button>
          </div>
        </div>
      </div>
    </div>
    <div :style="{'width': '1200px', 'margin': '0 auto', 'display': 'flex'}">
            <div class="con-line2">
        <div class="con-card">
          <div style="padding: 0 30px 0 30px;">
            <i class="el-icon-document" style=" font-size: 74px; color: #FFFFFF" />
          </div>
          <div style="color: #FFFFFF; font-size: 20px;">中小企业数字化<br>水平评测</div>
        </div>
        <div class="con-btn1">
<!--          <el-tag :type="question | testFilter">{{ question | testFormat }}</el-tag>-->
          <div>
            <router-link to="/digitalTast/testIndex"> <el-button type="primary">去自测</el-button></router-link>
          </div>
        </div>
      </div>
    </div>
    <div v-if="agentMobile" style="font-size: 20px; text-align: center; padding: 20px 0;">代理联系电话：{{agentMobile}}</div>
    <div style="font-size: 20px; text-align: center; padding: 20px 0;">建议使用Microsoft Edge或Google Chrome浏览器</div>
  </div>
</template>

<script>
import { index } from '@/api/home'
import { find2 } from '@/api/base'
export default {
  name: 'Homepage',
  filters: {
    baseFilter(status) {
      const statusMap = {
        1: 'success',
        0: 'warning'
      }
      return statusMap[status]
    },
    baseFormat(status) {
      const statusMap = {
        0: '待完善',
        1: '已完善'
      }
      return statusMap[status]
    },
    testFilter(status) {
      const statusMap = {
        1: 'success',
        0: 'warning'
      }
      return statusMap[status]
    },
    testFormat(status) {
      const statusMap = {
        0: '待填报',
        1: '已填报'
      }
      return statusMap[status]
    },
    testButton(status) {
      const statusMap = {
        1: 'warning',
        0: 'primary'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      fullscreenLoading: false,
      screenHeight: 500,
      agentMobile: '1',
      year: '',
      base: '0',
      test: '0',
      question: '0',
      baseBtn: '去完善',
      testBtn: '去填报',
      quesBtn: '去填报'
    }
  },
  created() {
    this.screenHeight = screen.height - 350
    this.find()
  },
  methods: {
    find() {
      index().then(response => {
        console.log(response)
        if (response.result === 1) {
          this.agentMobile = response.data.agentMobile
          console.log(this.agentMobile)
          this.year = response.data.year + '年度'
          this.base = response.data.base
          this.test = response.data.test
          this.question = response.data.questions
          if (this.base === '1') {
            this.baseBtn = '去修改'
          } else {
            this.baseBtn = '去完善'
          }
          if (this.test === '1') {
            this.testBtn = '重新填报'
          } else {
            this.testBtn = '去填报'
          }
          if (this.question === '1') {
            this.quesBtn = '重新填报'
          } else {
            this.quesBtn = '去填报'
          }
          this.fullscreenLoading = true
        } else {
          this.fullscreenLoading = true
        }
      }).catch(() => {
        this.fullscreenLoading = true
      })
    },
    toBase() {
      this.$router.push('/base/update')
    },
    toReview() {
      this.$router.push('/diagnosis/review')
    },
    baseFind(id) {
      find2().then(response => {
        if (response.result === 1) {
          if (id === 1) {
            this.$router.push('/diagnosis/promise')
          } else if (id === 2) {
            this.$router.push('/questionnaire/add')
          }
        } else if (response.result === 2) {
          this.$message({
            message: '请完善企业基本信息', type: 'warning'
          })
          return false
        } else {
          return false
        }
      })
    },
    showImage(id) {
      document.getElementById(id).style.display = 'block'
    },
    hideImage(id) {
      document.getElementById(id).style.display = 'none'
    }
  }
}
</script>
<style>
.con-line {
  width: 350px;
  height: 340px;
  border: 0 solid;
  border-radius: 10px;
  padding: 100px 30px 0 0;
}
.con-line2 {
  width: 350px;
  height: 340px;
  border: 0 solid;
  border-radius: 10px;
  padding: 20px 30px 0 0;
}
.con-card {
  width: 100%;
  height: 160px;
  background-color: #409EFF;
  display: flex;
  align-items: center;
}
.con-btn {
  background-color:#FFFFFF;
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  justify-content: space-between;
}
.con-btn1 {
  background-color:#FFFFFF;
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  flex-direction: column;
  justify-content: space-around;
}
.suspend-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 68px;
  height: 76px;
  border-radius: 2px;
  background-color: #fff;
  padding: 0 0 20px 0;
}
.icon-name {
  margin-top: 4px;
  line-height: 18px;
  font-size: 12px;
  color: #666;
}
</style>
